<template>
	<view class="content mainpadding">
		<!-- 持卡人 -->
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">姓名</view>
			<input class="titletext textright flex1" type="text" placeholder="请输入姓名" v-model="name">
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">身份证号</view>
			<input class="titletext textright flex1" type="text" placeholder="请输入身份证号" v-model="idcard">
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween" @click="yhdhshow=true">
			<view class="titletext xiaohei margin_right3">公司</view>
			<view class="flexright">
				<input class="titletext textright flex1" type="text" placeholder="请选择公司" disabled=""
					v-model="company_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff border margin_bottom3 flexbetween">
			<view class="titletext xiaohei margin_right3">险种</view>
			<view class="flexright">
				<input class="titletext textright flex1" type="text" placeholder="请选择险种" disabled=""
					v-model="user_gb_xz_name">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="submitbtn margin_top6" @click="submit()">
			确认
		</view>
		<view class="posibottom flexcenter mainpadding"  @click="checked=checked?false:true" >
			<!-- <view class="strongtext xiaohong margin-top">购保须知：{{config.buybxz}}</view> -->
			<uni-icons v-if="!checked"type="circle" size="24"></uni-icons>
			<uni-icons v-else type="checkbox-filled" color="#4A9CE7" size="24"></uni-icons>
			<text>请仔细阅读并勾选</text>
			<text class="colortext" @click.stop="userAgreement(3)">《购保须知》</text>
		</view>
		<u-picker :show="yhdhshow" :columns="yhdhcolumns" title="" @cancel="yhdhshow=false" @confirm="yhdhconfirm"
			keyName="name"></u-picker>
			<u-picker :show="xzshow" :columns="xzcolumns" title="" @cancel="xzshow=false" @confirm="xzconfirm"
				keyName="name"></u-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				name: "",
				idcard: "",
				company_id: "",
				company_name: "",
				user_gb_xz_id: "",
				user_gb_xz_name: "",
				yhdhcolumns: [],
				yhdhshow: false,
				xzcolumns: [],
				xzshow: false,
				config:{},
				checked:false
			}
		},
		onLoad(options) {
			this.user_gb_xz_id = options.id
			this.user_gb_xz_name = options.name
			// this.getConfigInfo()
			this.getyhdh()
			// this.getxz()
		},
		methods: {
			userAgreement(type){
				uni.navigateTo({
					url:'/pages/login/xy?type='+type
				})
			},
			getConfigInfo() {
				httpRequest.request('/api/index/getConfigInfo', 'GET', {}).then(res => {
					this.config = res.data
				})
			},
			getyhdh() {
				httpRequest.request('/api/user/companyIndex', 'GET', {}).then(res => {
					this.yhdhcolumns.push(res.data)
				})
			},
			yhdhconfirm(e) {
				this.company_name = e.value[0].name
				this.company_id = e.value[0].id
				this.yhdhshow = false
			},
			getxz() {
				httpRequest.request('/api/user/userGbXzIndex', 'GET', {}).then(res => {
					this.xzcolumns.push(res.data)
				})
			},
			xzconfirm(e) {
				this.user_gb_xz_name = e.value[0].name
				this.user_gb_xz_id = e.value[0].id
				this.xzshow = false
			},
			submit() {
				if (this.name == "") {
					httpRequest.toast("请输入姓名")
					return false
				}
				if (this.idcard == "") {
					httpRequest.toast("请输入身份证号")
					return false
				}
				if (this.company_id == "") {
					httpRequest.toast("请选择公司")
					return false
				}
				if (this.user_gb_xz_id == "") {
					httpRequest.toast("请选择险种")
					return false
				}
				if (this.checked == false) {
					httpRequest.toast("请仔细阅读并勾选")
					return false
				}
				let data = {
					name: this.name,
					idcard: this.idcard,
					company_id: this.company_id,
					user_gb_xz_id: this.user_gb_xz_id
				}
				let url = "/api/user/buyUserGb"
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.colortext{
		color: $uni-color-primary;
	}
	.content {
		padding-bottom: 150rpx;
	}

	.noSelect {
		width: 138rpx;
		height: 69rpx;
		line-height: 69rpx;
		text-align: center;
		background: rgba(102, 102, 102, .1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid rgba(102, 102, 102, .1);
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		margin-right: 30rpx;
		color: #666666;
	}

	.select {
		width: 138rpx;
		height: 69rpx;
		line-height: 69rpx;
		text-align: center;
		background: rgba(255, 133, 5, 0.1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #FF8505;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		margin-right: 30rpx;
		position: relative;
	}

	.select::after {
		content: '';
		width: 25rpx;
		height: 20rpx;
		// background-image: url("/static/images/mine/invoice_select.png");
		background-size: 100% 100%;
		position: absolute;
		right: 0;
		bottom: 0;
	}

	.item_image_box {
		width: 33.33%;
	}

	.item_image {
		position: relative;
		width: 180rpx;
		height: 180rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>